/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vistas;

import controladores.VehiculoJpaController;
import entidades.Categoria;
import entidades.Chofer;
import entidades.ConfiguracionEjes;
import entidades.EstadoVehiculo;
import entidades.Funcionalidad;
import entidades.Marca;
import entidades.Modelo;
import entidades.Obra;
import entidades.Propietario;
import entidades.Vehiculo;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
import reportes.GenReportes;
import rn.RepuestoRN;
import rn.VehiculoRN;
import static vistas.Principal.usuario;

/**
 *
 * @author Pablo
 */
public class ParqueAutomotor extends javax.swing.JFrame {

    private Vehiculo vehiculo, vehiculo_seleccionado;
    DefaultTableModel modelo_de_tabla;
    private int opcion_modificar = 0;
    private ConfiguracionEjes config;
    List<Funcionalidad> func_hab;

    public ParqueAutomotor() {
        initComponents();

        vehiculo = new Vehiculo();
        bt_modificar.setEnabled(false);
        bt_eliminar.setEnabled(false);
                
        tf_descripcion.addKeyListener(new CambiarCampo());
        tf_nro_unidad.addKeyListener(new CambiarCampo());
        tf_chapa.addKeyListener(new CambiarCampo());
        tf_motor.addKeyListener(new CambiarCampo());
        tf_nro_chasis.addKeyListener(new CambiarCampo());        
        combo_marca.addKeyListener(new CambiarCampo());
        combo_modelo.addKeyListener(new CambiarCampo());
        combo_categoria.addKeyListener(new CambiarCampo());
        combo_chofer.addKeyListener(new CambiarCampo());
        combo_obra.addKeyListener(new CambiarCampo());
        combo_propietario.addKeyListener(new CambiarCampo());
        combo_estado.addKeyListener(new CambiarCampo());
        bt_grabar.addKeyListener(new GrabarRegistro());        

        tf_descripcion.setDocument(new JTextFieldToUpperCase());
        tf_nro_unidad.setDocument(new JTextFieldToUpperCase());
        tf_chapa.setDocument(new JTextFieldToUpperCase());
        tf_nro_chasis.setDocument(new JTextFieldToUpperCase());
        tf_motor.setDocument(new JTextFieldToUpperCase());

        tf_descripcion.getDocument().putProperty("campoDelEvento", "descripcion");
        tf_descripcion.getDocument().addDocumentListener(new TexChangeListener());
        tf_descripcion.addKeyListener(new KeyPressedClass());
        tf_nro_unidad.getDocument().putProperty("campoDelEvento", "nro_unidad");
        tf_nro_unidad.getDocument().addDocumentListener(new TexChangeListener());
        tf_nro_unidad.addKeyListener(new KeyPressedClass());
        tf_chapa.getDocument().putProperty("campoDelEvento", "nro_chapa");
        tf_chapa.getDocument().addDocumentListener(new TexChangeListener());
        tf_chapa.addKeyListener(new KeyPressedClass());
        tf_nro_chasis.getDocument().putProperty("campoDelEvento", "nro_chasis");
        tf_nro_chasis.getDocument().addDocumentListener(new TexChangeListener());
        tf_nro_chasis.addKeyListener(new KeyPressedClass());

        tabla_conincidencias.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
        tabla_conincidencias.getActionMap().put("Enter", new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                System.out.println("Se presiono la tecla enter");
                int fila = tabla_conincidencias.getSelectedRow();
                String s_id = (String) tabla_conincidencias.getValueAt(fila, 0);
                vehiculo_seleccionado = VehiculoRN.findVehiculoPorID(new Long(s_id));
                llenarCampos(vehiculo_seleccionado);
                habilitarCampos(false);
                bt_grabar.setEnabled(false);
                bt_modificar.setEnabled(true);
                //bt_eliminar.setEnabled(true);
                tabla_conincidencias.requestFocus();
                tabla_conincidencias.changeSelection(fila, 0, false, false);
            }
        });

        //Para accionar con doble clic
        tabla_conincidencias.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
                JTable table = (JTable) me.getSource();
                Point p = me.getPoint();
                int row = table.rowAtPoint(p);
                if (me.getClickCount() == 2) {
                    String s_id = (String) tabla_conincidencias.getValueAt(row, 0);
                    vehiculo_seleccionado = VehiculoRN.findVehiculoPorID(new Long(s_id));
                    llenarCampos(vehiculo_seleccionado);
                    habilitarCampos(false);
                    bt_grabar.setEnabled(false);
                    bt_modificar.setEnabled(true);
                    //bt_eliminar.setEnabled(true);
                    tabla_conincidencias.requestFocus();
                    tabla_conincidencias.changeSelection(row, 0, false, false);
                }
            }
        });

        llenarCombos();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        tf_descripcion.requestFocus();
        func_hab = usuario.getFuncionalidads();
        bloquearFunciones();
    }

    private boolean estaHabilitado(String func) {
        for (Funcionalidad f : func_hab) {
            if (f.getNombre().equals(func)) {
                return true;
            }
        }
        return false;
    }

    private void bloquearFunciones() {
        if (!estaHabilitado("Parque automotor ABM")) {
            bt_add_categoria.setEnabled(false);
            bt_add_marca.setEnabled(false);
            bt_add_modelo.setEnabled(false);
            bt_config.setEnabled(false);
            bt_eliminar.setVisible(false);
            bt_estado.setEnabled(false);
            bt_grabar.setVisible(false);
            bt_modificar.setVisible(false);
            bt_propietario.setEnabled(false);
            bt_obra.setEnabled(false);
            bt_chofer.setEnabled(false);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        tf_combustible_actual1 = new javax.swing.JTextField();
        bt_ingresar1 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        tf_combustible_actual4 = new javax.swing.JTextField();
        bt_cancelar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        tf_descripcion = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        tf_chapa = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        tf_nro_unidad = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        combo_modelo = new javax.swing.JComboBox();
        combo_modelo_anio = new javax.swing.JComboBox();
        combo_categoria = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        combo_propietario = new javax.swing.JComboBox();
        bt_add_marca = new javax.swing.JButton();
        bt_add_modelo = new javax.swing.JButton();
        bt_add_categoria = new javax.swing.JButton();
        bt_propietario = new javax.swing.JButton();
        bt_grabar = new javax.swing.JButton();
        bt_limpiar = new javax.swing.JButton();
        bt_modificar = new javax.swing.JButton();
        tf_motor = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        combo_chofer = new javax.swing.JComboBox();
        bt_chofer = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();
        tf_nro_chasis = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        combo_obra = new javax.swing.JComboBox();
        bt_obra = new javax.swing.JButton();
        bt_eliminar = new javax.swing.JButton();
        combo_marca = new javax.swing.JComboBox();
        radio_sin_chapa = new javax.swing.JRadioButton();
        radio_sin_nrp_motor = new javax.swing.JRadioButton();
        radio_sin_chasis = new javax.swing.JRadioButton();
        jLabel23 = new javax.swing.JLabel();
        combo_estado = new javax.swing.JComboBox();
        bt_estado = new javax.swing.JButton();
        jLabel24 = new javax.swing.JLabel();
        tf_config = new javax.swing.JTextField();
        bt_config = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        tabla_conincidencias = new javax.swing.JTable();
        bt_imprimir_lista = new javax.swing.JButton();
        bt_exportar_excel = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        combo_listados = new javax.swing.JComboBox();
        tx_obra = new javax.swing.JLabel();
        combo_obra_filtro = new javax.swing.JComboBox();
        combo_categoria_filtro = new javax.swing.JComboBox();
        tx_categoria = new javax.swing.JLabel();
        tx_propietario = new javax.swing.JLabel();
        combo_propietario_filtro = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel3.setText("Combustible Actual (M3):");

        tf_combustible_actual1.setEnabled(false);

        bt_ingresar1.setText("INGRESAR");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel5.setText("Ingreso (M3):");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("Ingreso (M3):");

        tf_combustible_actual4.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        bt_cancelar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        bt_cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/cancel.png"))); // NOI18N
        bt_cancelar.setText("CANCELAR");
        bt_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelarActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(0, 0, 153));

        jLabel2.setBackground(new java.awt.Color(255, 255, 255));
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("VEHÍCULOS");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        tf_descripcion.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Descripción *:");

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel12.setText("Chapa *:");

        tf_chapa.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel13.setText("Nº Legajo *:");

        tf_nro_unidad.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jLabel14.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel14.setText(" Marca:");

        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel15.setText("Modelo (Año):");
        jLabel15.setEnabled(false);

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel16.setText("Modelo:");

        combo_modelo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        combo_modelo_anio.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        combo_modelo_anio.setEnabled(false);

        combo_categoria.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel17.setText("Propietario:");

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel18.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel18.setText("Categoria:");

        combo_propietario.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        bt_add_marca.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        bt_add_marca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_add_marcaActionPerformed(evt);
            }
        });

        bt_add_modelo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        bt_add_modelo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_add_modeloActionPerformed(evt);
            }
        });

        bt_add_categoria.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        bt_add_categoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_add_categoriaActionPerformed(evt);
            }
        });

        bt_propietario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        bt_propietario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_propietarioActionPerformed(evt);
            }
        });

        bt_grabar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        bt_grabar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/accept.png"))); // NOI18N
        bt_grabar.setText("GRABAR");
        bt_grabar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_grabarActionPerformed(evt);
            }
        });

        bt_limpiar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        bt_limpiar.setText("LIMPIAR");
        bt_limpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_limpiarActionPerformed(evt);
            }
        });

        bt_modificar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        bt_modificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png"))); // NOI18N
        bt_modificar.setText("MODIFICAR");
        bt_modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_modificarActionPerformed(evt);
            }
        });

        tf_motor.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel19.setText("Dom/Motor *:");

        jLabel20.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel20.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel20.setText("Chofer actual:");

        combo_chofer.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        bt_chofer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        bt_chofer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_choferActionPerformed(evt);
            }
        });

        jLabel21.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel21.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel21.setText(" Nº Chasis *:");

        tf_nro_chasis.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tf_nro_chasis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_nro_chasisActionPerformed(evt);
            }
        });

        jLabel22.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel22.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel22.setText("Obra actual:");

        combo_obra.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        bt_obra.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        bt_obra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_obraActionPerformed(evt);
            }
        });

        bt_eliminar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        bt_eliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        bt_eliminar.setText("ELIMIMAR");
        bt_eliminar.setEnabled(false);
        bt_eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_eliminarActionPerformed(evt);
            }
        });

        combo_marca.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        combo_marca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo_marcaActionPerformed(evt);
            }
        });

        radio_sin_chapa.setText("Sin Chapa");
        radio_sin_chapa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radio_sin_chapaActionPerformed(evt);
            }
        });

        radio_sin_nrp_motor.setText("Sin Nº");
        radio_sin_nrp_motor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radio_sin_nrp_motorActionPerformed(evt);
            }
        });

        radio_sin_chasis.setText("Sin Nº");
        radio_sin_chasis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radio_sin_chasisActionPerformed(evt);
            }
        });

        jLabel23.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel23.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel23.setText("Estado:");

        combo_estado.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        combo_estado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo_estadoActionPerformed(evt);
            }
        });

        bt_estado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        bt_estado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_estadoActionPerformed(evt);
            }
        });

        jLabel24.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel24.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel24.setText("Configuración de ejes:");
        jLabel24.setEnabled(false);

        tf_config.setEditable(false);
        tf_config.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tf_config.setEnabled(false);
        tf_config.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_configActionPerformed(evt);
            }
        });

        bt_config.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/arrow_redo.png"))); // NOI18N
        bt_config.setEnabled(false);
        bt_config.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_configActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel16)
                            .addComponent(jLabel15)
                            .addComponent(jLabel14)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(combo_modelo_anio, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(tf_descripcion, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tf_nro_unidad, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(combo_modelo, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(combo_marca, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(bt_add_marca, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(bt_add_modelo, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(tf_chapa, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(radio_sin_chapa))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(bt_eliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(combo_categoria, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(combo_propietario, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(7, 7, 7)
                                .addComponent(bt_add_categoria, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(bt_propietario, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel21, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tf_nro_chasis, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tf_motor, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(58, 58, 58)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(radio_sin_nrp_motor, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(radio_sin_chasis, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(bt_chofer, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(35, 35, 35)
                                .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(combo_chofer, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(7, 7, 7)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(combo_estado, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(combo_obra, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(tf_config))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bt_obra, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(bt_estado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(bt_modificar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_limpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_grabar))
                    .addComponent(bt_config, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_chapa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(radio_sin_chapa))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_nro_unidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel14)
                        .addComponent(combo_marca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(bt_add_marca))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel16)
                        .addComponent(combo_modelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(bt_add_modelo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(combo_modelo_anio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(combo_categoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel18))
                    .addComponent(bt_add_categoria, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(combo_propietario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel17))
                    .addComponent(bt_propietario, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_motor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(radio_sin_nrp_motor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tf_nro_chasis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel21))
                    .addComponent(radio_sin_chasis))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(combo_chofer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel20))
                    .addComponent(bt_chofer, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(combo_obra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel22))
                    .addComponent(bt_obra, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bt_estado, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(combo_estado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel23)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bt_config, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tf_config, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel24)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_grabar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_limpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_modificar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_eliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        tabla_conincidencias.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane4.setViewportView(tabla_conincidencias);

        bt_imprimir_lista.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        bt_imprimir_lista.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/printer.png"))); // NOI18N
        bt_imprimir_lista.setText("IMPRIMIR LISTA");
        bt_imprimir_lista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_imprimir_listaActionPerformed(evt);
            }
        });

        bt_exportar_excel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        bt_exportar_excel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/page_excel.png"))); // NOI18N
        bt_exportar_excel.setText("EXPORTAR A EXCEL");
        bt_exportar_excel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_exportar_excelActionPerformed(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Listar"));

        combo_listados.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        combo_listados.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar...", "Todos", "Vehiculos en Planta", "Propietario:", "Vehiculos en obra:", "Categoria:" }));
        combo_listados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo_listadosActionPerformed(evt);
            }
        });

        tx_obra.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tx_obra.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        tx_obra.setText("Obra actual:");
        tx_obra.setEnabled(false);

        combo_obra_filtro.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        combo_obra_filtro.setEnabled(false);
        combo_obra_filtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo_obra_filtroActionPerformed(evt);
            }
        });

        combo_categoria_filtro.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        combo_categoria_filtro.setEnabled(false);
        combo_categoria_filtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo_categoria_filtroActionPerformed(evt);
            }
        });

        tx_categoria.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tx_categoria.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        tx_categoria.setText("Categ.:");
        tx_categoria.setEnabled(false);

        tx_propietario.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tx_propietario.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        tx_propietario.setText("Propietariol:");
        tx_propietario.setEnabled(false);

        combo_propietario_filtro.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        combo_propietario_filtro.setEnabled(false);
        combo_propietario_filtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo_propietario_filtroActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(combo_listados, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tx_obra))
                    .addComponent(tx_propietario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(combo_propietario_filtro, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(combo_obra_filtro, 0, 169, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tx_categoria)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(combo_categoria_filtro, 0, 168, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(combo_categoria_filtro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tx_categoria))
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(combo_listados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(combo_obra_filtro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tx_obra)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(combo_propietario_filtro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tx_propietario)))
        );

        jLabel1.setText("* Campos obligatorios");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 605, Short.MAX_VALUE)
                        .addComponent(bt_exportar_excel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_imprimir_lista)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_cancelar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane4))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(bt_cancelar, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                        .addComponent(bt_imprimir_lista, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(bt_exportar_excel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabel1))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public boolean verificarDatosVehiculo(Vehiculo v, Long id_excepcion) {
        boolean b = true;
        if (VehiculoRN.yaExiste(v.getDescripcion(), VehiculoJpaController.DESCRIPCION, id_excepcion)) {
            b = false;
            mostrarMensaje("Ya existe un vehiculo con la misma 'descripción'");
        }
        if (!radio_sin_chapa.isSelected()) {
            if (VehiculoRN.yaExiste(v.getChapa(), VehiculoJpaController.NRO_CHAPA, id_excepcion)) {
                b = false;
                mostrarMensaje("Ya existe un vehiculo con la misma 'chapa'");
            }
        }
        if (!radio_sin_chasis.isSelected()) {
            if (VehiculoRN.yaExiste(v.getNro_chasis(), VehiculoJpaController.CHASIS, id_excepcion)) {
                b = false;
                mostrarMensaje("Ya existe un vehiculo con la misma 'chasis'");
            }
        }
        if (!radio_sin_nrp_motor.isSelected()) {
            if (VehiculoRN.yaExiste(v.getNro_unidad(), VehiculoJpaController.NRO_UNIDAD, id_excepcion)) {
                b = false;
                mostrarMensaje("Ya existe un vehiculo con la misma 'nro_unidad'");
            }
        }
        return b;
    }

    private void bt_grabarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_grabarActionPerformed
        grabar();

    }//GEN-LAST:event_bt_grabarActionPerformed

    
    private void grabar(){
        if (chaquearCamposRequeridos()) {
            setearVehiculo();
            Long id_excep = null;
            if (opcion_modificar == 1) {
                id_excep = vehiculo_seleccionado.getId();
            }
            if (verificarDatosVehiculo(vehiculo, id_excep)) {
                if (opcion_modificar == 1) {
                    vehiculo.setId(vehiculo_seleccionado.getId());
                    VehiculoRN.edit(vehiculo);
                    mostrarMensaje("Datos Modificados!!!");
                    opcion_modificar = 0;
                } else {
                    VehiculoRN.create(vehiculo);
                    mostrarMensaje("Registro Guardado!!!");
                    opcion_modificar = 0;
                }
                limpiarCampos();
                vehiculo = new Vehiculo();
                bt_modificar.setEnabled(false);
                tf_descripcion.requestFocus();
            }
            vehiculo_seleccionado = null;
        } else {
            mostrarMensaje("Campos requeridos no pueden estar vacios!!!");
            tf_descripcion.requestFocus();
        }
    }
    
    
    private void bt_limpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_limpiarActionPerformed
        limpiarCampos();
        iniciarModeloTabla();
        tabla_conincidencias.setModel(modelo_de_tabla);
        habilitarCampos(true);
        bt_grabar.setEnabled(true);
        bt_modificar.setEnabled(false);
        bt_eliminar.setEnabled(false);
        opcion_modificar = 0;
        vehiculo_seleccionado = null;
        tf_descripcion.requestFocus();
    }//GEN-LAST:event_bt_limpiarActionPerformed

    private void bt_modificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_modificarActionPerformed
        habilitarCampos(true);
        bt_grabar.setEnabled(true);
        opcion_modificar = 1;
    }//GEN-LAST:event_bt_modificarActionPerformed

    private void bt_eliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_eliminarActionPerformed
        if (vehiculo_seleccionado != null) {
            int c = JOptionPane.showConfirmDialog(null, "¿Está seguro de eliminar el rodado?");
            if (c == 0) {
                VehiculoRN.eliminar(vehiculo_seleccionado.getId());
                mostrarMensaje("Rodado eliminado!!!");
                limpiarCampos();
                habilitarCampos(true);
                bt_grabar.setEnabled(true);
                bt_modificar.setEnabled(false);
                bt_eliminar.setEnabled(false);
                vehiculo_seleccionado = null;
                tf_descripcion.requestFocus();
            }
        } else {
            mostrarMensaje("Debe seleccionar un rodado");
        }
    }//GEN-LAST:event_bt_eliminarActionPerformed

    private void combo_listadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo_listadosActionPerformed
        List<Vehiculo> resultado = new ArrayList();
        String item_selected = (String) combo_listados.getSelectedItem();
        if (!item_selected.equals("Seleccionar...")) {
            switch (item_selected) {
                case "Todos":
                    habilitarFiltro(false);
                    resultado = VehiculoRN.getTodosVechiculos();
                    break;
                case "Vehículos de Hormicat":
                    habilitarFiltro(false);
                    resultado = VehiculoRN.getVehiculosPor("HORMICAT S.A", "Propietario");
                    break;
                case "Vehículos externos":
                    habilitarFiltro(false);
                    resultado = VehiculoRN.getVehiculosPor("Hormicat S.A.", item_selected);
                    break;
                case "Vehiculos en Planta":
                    habilitarFiltro(false);
                    resultado = VehiculoRN.getVehiculosPor("Planta", "Obra");
                    break;
                case "Propietario:":
                    tx_obra.setEnabled(false);
                    combo_obra_filtro.setEnabled(false);
                    tx_categoria.setEnabled(false);
                    combo_categoria_filtro.setEnabled(false);
                    tx_propietario.setEnabled(true);
                    combo_propietario_filtro.setEnabled(true);
                    break;
                case "Vehiculos en obra:":
                    tx_obra.setEnabled(true);
                    combo_obra_filtro.setEnabled(true);
                    tx_categoria.setEnabled(false);
                    combo_categoria_filtro.setEnabled(false);
                    tx_propietario.setEnabled(false);
                    combo_propietario_filtro.setEnabled(false);
                    break;
                case "Categoria:":
                    tx_categoria.setEnabled(true);
                    combo_categoria_filtro.setEnabled(true);
                    tx_obra.setEnabled(false);
                    combo_obra_filtro.setEnabled(false);
                    tx_propietario.setEnabled(false);
                    combo_propietario_filtro.setEnabled(false);
                    break;
                case "Autos":
                    habilitarFiltro(false);
                    resultado = VehiculoRN.getVehiculosPor("Auto", "Categoria");
                    break;
                case "Camiones":
                    habilitarFiltro(false);
                    resultado = VehiculoRN.getVehiculosPor("Camion", "Categoria");
                    break;
                case "Hormigoneros":
                    habilitarFiltro(false);
                    resultado = VehiculoRN.getVehiculosPor("Hormigonero", "Categoria");
                    break;
            }
            llenarTablaResultado(resultado);
        }
    }//GEN-LAST:event_combo_listadosActionPerformed

    private void habilitarFiltro(boolean b) {
        tx_obra.setEnabled(b);
        combo_obra_filtro.setEnabled(b);
        tx_categoria.setEnabled(b);
        combo_categoria_filtro.setEnabled(b);
        tx_propietario.setEnabled(b);
        combo_propietario_filtro.setEnabled(b);
    }

    private void combo_obra_filtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo_obra_filtroActionPerformed
        List<Vehiculo> resultado = new ArrayList();
        Obra item_selected = (Obra) combo_obra_filtro.getSelectedItem();
        resultado = VehiculoRN.getVehiculosPor(item_selected.toString(), "Obra");
        llenarTablaResultado(resultado);
    }//GEN-LAST:event_combo_obra_filtroActionPerformed

    private void bt_imprimir_listaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_imprimir_listaActionPerformed
        String item_selected = (String) combo_listados.getSelectedItem();
        GenReportes gen = new GenReportes();
        if (!item_selected.equals("Seleccionar...")) {
            switch (item_selected) {
                case "Todos":
                    gen.repTodosVehiculos();
                    break;
                case "Vehículos de Hormicat":
                    gen.repVehiculosHormicat();
                    break;
                case "Vehículos externos":
                    gen.repVehiculosExternosAHormicat();
                    break;
                case "Vehiculos en Planta":
                    gen.repVehiculosEnObra("Planta");
                    break;
                case "Vehiculos en obra:":
                    Obra item = (Obra) combo_obra_filtro.getSelectedItem();
                    gen.repVehiculosEnObra(item.getDescripcion());
                    break;
                case "Categoria:":
                    Categoria i = (Categoria) combo_categoria_filtro.getSelectedItem();
                    gen.repVehiculosPorCategoria(i.getDescripcion());
                    break;
                case "Propietario:":
                    Propietario it = (Propietario) combo_propietario_filtro.getSelectedItem();
                    gen.repVehiculosPorPropietario(it.getDescripcion());
                    break;
                case "Autos":

                    break;
                case "Camiones":

                    break;
                case "Hormigoneros":

                    break;
            }
        }
    }//GEN-LAST:event_bt_imprimir_listaActionPerformed

    private void combo_categoria_filtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo_categoria_filtroActionPerformed
        List<Vehiculo> resultado = new ArrayList();
        Categoria item_selected = (Categoria) combo_categoria_filtro.getSelectedItem();
        resultado = VehiculoRN.getVehiculosPor(item_selected.toString(), "Categoria");
        llenarTablaResultado(resultado);
    }//GEN-LAST:event_combo_categoria_filtroActionPerformed

    private void bt_exportar_excelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_exportar_excelActionPerformed

    }//GEN-LAST:event_bt_exportar_excelActionPerformed

    private void combo_propietario_filtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo_propietario_filtroActionPerformed
        List<Vehiculo> resultado = new ArrayList();
        Propietario item_selected = (Propietario) combo_propietario_filtro.getSelectedItem();
        resultado = VehiculoRN.getVehiculosPor(item_selected.toString(), "Propietario");
        llenarTablaResultado(resultado);
    }//GEN-LAST:event_combo_propietario_filtroActionPerformed

    private void bt_add_modeloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_add_modeloActionPerformed
        new ABM_Modelos(this, (Marca) combo_marca.getSelectedItem());
    }//GEN-LAST:event_bt_add_modeloActionPerformed

    private void bt_add_marcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_add_marcaActionPerformed
        new ABM_Marcas(this);
    }//GEN-LAST:event_bt_add_marcaActionPerformed

    private void combo_marcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo_marcaActionPerformed
        if (combo_marca.getSelectedItem() != null) {
            Marca item_selected = (Marca) combo_marca.getSelectedItem();
            List<Modelo> modelos = VehiculoRN.getModelosPorMarca(item_selected.getId());
            combo_modelo.removeAllItems();
            for (Modelo m : modelos) {
                combo_modelo.addItem(m);
            }
        }
    }//GEN-LAST:event_combo_marcaActionPerformed

    private void bt_add_categoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_add_categoriaActionPerformed
        new ABM_Categorias(this);
    }//GEN-LAST:event_bt_add_categoriaActionPerformed

    private void bt_propietarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_propietarioActionPerformed
        new ABM_Propietarios(this);
    }//GEN-LAST:event_bt_propietarioActionPerformed

    private void bt_choferActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_choferActionPerformed
        new ABM_Chofers(this);
    }//GEN-LAST:event_bt_choferActionPerformed

    private void bt_obraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_obraActionPerformed
        new ABM_Obras(this);
    }//GEN-LAST:event_bt_obraActionPerformed

    private void bt_estadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_estadoActionPerformed
        new ABM_EstadosVehiculos(this);
    }//GEN-LAST:event_bt_estadoActionPerformed

    private void radio_sin_chapaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radio_sin_chapaActionPerformed
        if (radio_sin_chapa.isSelected()) {
            tf_chapa.setEnabled(false);
            tf_chapa.setText("No Asig.");
        } else {
            tf_chapa.setEnabled(true);
            tf_chapa.setText("");
        }
    }//GEN-LAST:event_radio_sin_chapaActionPerformed

    private void radio_sin_nrp_motorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radio_sin_nrp_motorActionPerformed
        if (radio_sin_nrp_motor.isSelected()) {
            tf_motor.setEnabled(false);
            tf_motor.setText("No Asig.");
        } else {
            tf_motor.setEnabled(true);
            tf_motor.setText("");
        }
    }//GEN-LAST:event_radio_sin_nrp_motorActionPerformed

    private void tf_nro_chasisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_nro_chasisActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_nro_chasisActionPerformed

    private void radio_sin_chasisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radio_sin_chasisActionPerformed
        if (radio_sin_chasis.isSelected()) {
            tf_nro_chasis.setEnabled(false);
            tf_nro_chasis.setText("No Asig.");
        } else {
            tf_nro_chasis.setEnabled(true);
            tf_nro_chasis.setText("");
        }
    }//GEN-LAST:event_radio_sin_chasisActionPerformed

    private void combo_estadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo_estadoActionPerformed

    }//GEN-LAST:event_combo_estadoActionPerformed

    private void bt_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_bt_cancelarActionPerformed

    private void tf_configActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_configActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_configActionPerformed

    private void bt_configActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_configActionPerformed
        new ViewConfiguracionDeEjes(this);
    }//GEN-LAST:event_bt_configActionPerformed

    public void setConfigEjes(ConfiguracionEjes config) {
        this.config = config;
        tf_config.setText(config.getDesignacion());
    }

    private void setearVehiculo() {
        //Fields
        vehiculo.setDescripcion(tf_descripcion.getText());
        vehiculo.setChapa(tf_chapa.getText());
        vehiculo.setDom_motor(tf_motor.getText());
        vehiculo.setNro_unidad(tf_nro_unidad.getText());
        vehiculo.setNro_chasis(tf_nro_chasis.getText());
        vehiculo.setConfiguracionEjes(config);

        //Combos
        vehiculo.setCategoria((Categoria) combo_categoria.getSelectedItem());
        vehiculo.setModelo((Modelo) combo_modelo.getSelectedItem());
        vehiculo.setPropietario((Propietario) combo_propietario.getSelectedItem());
        vehiculo.setChofer((Chofer) combo_chofer.getSelectedItem());
        vehiculo.setObra((Obra) combo_obra.getSelectedItem());
        vehiculo.setModelo_anio((String) combo_modelo_anio.getSelectedItem());
        vehiculo.setEstadoVehiculo((EstadoVehiculo) combo_estado.getSelectedItem());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_add_categoria;
    private javax.swing.JButton bt_add_marca;
    private javax.swing.JButton bt_add_modelo;
    private javax.swing.JButton bt_cancelar;
    private javax.swing.JButton bt_chofer;
    private javax.swing.JButton bt_config;
    private javax.swing.JButton bt_eliminar;
    private javax.swing.JButton bt_estado;
    private javax.swing.JButton bt_exportar_excel;
    private javax.swing.JButton bt_grabar;
    private javax.swing.JButton bt_imprimir_lista;
    private javax.swing.JButton bt_ingresar1;
    private javax.swing.JButton bt_limpiar;
    private javax.swing.JButton bt_modificar;
    private javax.swing.JButton bt_obra;
    private javax.swing.JButton bt_propietario;
    public static javax.swing.JComboBox combo_categoria;
    private javax.swing.JComboBox combo_categoria_filtro;
    public static javax.swing.JComboBox combo_chofer;
    public static javax.swing.JComboBox combo_estado;
    private javax.swing.JComboBox combo_listados;
    public javax.swing.JComboBox combo_marca;
    public static javax.swing.JComboBox combo_modelo;
    private javax.swing.JComboBox combo_modelo_anio;
    public static javax.swing.JComboBox combo_obra;
    private javax.swing.JComboBox combo_obra_filtro;
    public static javax.swing.JComboBox combo_propietario;
    private javax.swing.JComboBox combo_propietario_filtro;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JRadioButton radio_sin_chapa;
    private javax.swing.JRadioButton radio_sin_chasis;
    private javax.swing.JRadioButton radio_sin_nrp_motor;
    private javax.swing.JTable tabla_conincidencias;
    private javax.swing.JTextField tf_chapa;
    private javax.swing.JTextField tf_combustible_actual1;
    private javax.swing.JTextField tf_combustible_actual4;
    private javax.swing.JTextField tf_config;
    private javax.swing.JTextField tf_descripcion;
    private javax.swing.JTextField tf_motor;
    private javax.swing.JTextField tf_nro_chasis;
    private javax.swing.JTextField tf_nro_unidad;
    private javax.swing.JLabel tx_categoria;
    private javax.swing.JLabel tx_obra;
    private javax.swing.JLabel tx_propietario;
    // End of variables declaration//GEN-END:variables

    private boolean chaquearCamposRequeridos() {

        ArrayList<JTextField> campos_requeridos = new ArrayList();
        campos_requeridos.add(tf_descripcion);
        campos_requeridos.add(tf_chapa);
        campos_requeridos.add(tf_nro_unidad);
        campos_requeridos.add(tf_motor);
        campos_requeridos.add(tf_nro_chasis);

        for (JTextField t : campos_requeridos) {
            if (t.getText().startsWith(" ") || t.getText().isEmpty()) {
                return false;
            }
        }
//        if (this.config == null) {
//            return false;
//        }

        return true;
    }

    private void limpiarCampos() {
        tf_descripcion.setText(null);
        tf_chapa.setText(null);
        tf_motor.setText(null);
        tf_nro_unidad.setText(null);
        tf_nro_chasis.setText(null);

    }

    private void mostrarMensaje(String mensaje) {
        JOptionPane.showMessageDialog(null, mensaje);
    }

    private void llenarCombos() {
        List<Categoria> todosCategoria = VehiculoRN.getTodosCategoria();
        List<Chofer> todosChofer = VehiculoRN.getTodosChofer();
        List<Marca> todosMarca = VehiculoRN.getTodosMarca();
        List<Modelo> todosModelo = VehiculoRN.getTodosModelo();
        List<Obra> todosObra = VehiculoRN.getTodosObra();
        List<Propietario> todosPropietario = VehiculoRN.getTodosPropietario();
        List<EstadoVehiculo> todosEstadoVehiculo = VehiculoRN.getTodosEstadoVehiculo();

        llenarCombo(combo_categoria, todosCategoria);
        llenarCombo(combo_propietario, todosPropietario);
        llenarCombo(combo_marca, todosMarca);
        llenarCombo(combo_chofer, todosChofer);
        llenarCombo(combo_obra, todosObra);
        llenarCombo(combo_obra_filtro, todosObra);
        llenarCombo(combo_categoria_filtro, todosCategoria);
        llenarCombo(combo_propietario_filtro, todosPropietario);
        llenarCombo(combo_estado, todosEstadoVehiculo);
    }

    public void llenarCombo(JComboBox combo, List lista) {
        for (Object c : lista) {
            combo.addItem(c);
        }
    }

    private void llenarTablaResultado(List<Vehiculo> resultado) {
        iniciarModeloTabla();
        for (Vehiculo c : resultado) {

            String fila[] = new String[]{
                c.getId().toString(), c.getDescripcion(), c.getNro_unidad(), c.getChapa(), c.getNro_chasis()
            };
            modelo_de_tabla.addRow(fila);
        }
        tabla_conincidencias.setModel(modelo_de_tabla);
        iniciarModeloColumna();

    }

    public class TexChangeListener implements DocumentListener {

        public void insertUpdate(javax.swing.event.DocumentEvent evt) {
            LlenarTablaConicidencias(evt);
        }

        public void removeUpdate(javax.swing.event.DocumentEvent evt) {
            LlenarTablaConicidencias(evt);
        }

        public void changedUpdate(javax.swing.event.DocumentEvent evt) {
            LlenarTablaConicidencias(evt);
        }
    }

    private void iniciarModeloTabla() {
        Object datos[][] = {};
        String[] columnNames = {"Id", "Descripcion", "Nº Unidad", "Nº Chapa", "Nº Chasis"};
        modelo_de_tabla = new DefaultTableModel(datos, columnNames);
    }

    private void iniciarModeloColumna() {
        TableColumnModel columnModel = tabla_conincidencias.getColumnModel();
        columnModel.getColumn(0).setPreferredWidth(10);
        columnModel.getColumn(2).setPreferredWidth(20);
        columnModel.getColumn(3).setPreferredWidth(20);
        columnModel.getColumn(4).setPreferredWidth(20);
    }

    public void LlenarTablaConicidencias(javax.swing.event.DocumentEvent evt) {

        String campo_del_evento = (String) evt.getDocument().getProperty("campoDelEvento");
        List<Vehiculo> listaPersonas = new ArrayList<>();

        if (campo_del_evento.equals("descripcion")) {
            listaPersonas = VehiculoRN.getVehiculosLike(tf_descripcion.getText(), VehiculoJpaController.DESCRIPCION);
        }
        if (campo_del_evento.equals("nro_unidad")) {
            listaPersonas = VehiculoRN.getVehiculosLike(tf_nro_unidad.getText(), VehiculoJpaController.NRO_UNIDAD);
        }
        if (campo_del_evento.equals("nro_chasis")) {
            listaPersonas = VehiculoRN.getVehiculosLike(tf_nro_chasis.getText(), VehiculoJpaController.CHASIS);
        }
        if (campo_del_evento.equals("nro_chapa")) {
            listaPersonas = VehiculoRN.getVehiculosLike(tf_chapa.getText(), VehiculoJpaController.NRO_CHAPA);
        }

        iniciarModeloTabla();

        for (Vehiculo c : listaPersonas) {

            String fila[] = new String[]{
                c.getId().toString(), c.getDescripcion(), c.getNro_unidad(), c.getChapa(), c.getNro_chasis()
            };
            modelo_de_tabla.addRow(fila);
        }
        tabla_conincidencias.setModel(modelo_de_tabla);
        iniciarModeloColumna();
    }

    public class KeyPressedClass implements KeyListener {

        @Override
        public void keyTyped(KeyEvent e) {
            accion(e);
        }

        @Override
        public void keyPressed(KeyEvent e) {
            accion(e);
        }

        @Override
        public void keyReleased(KeyEvent e) {
            accion(e);
        }

        public void accion(KeyEvent e) {
            if (e.getSource() == tf_descripcion || e.getSource() == tf_nro_unidad) {
                if (e.VK_DOWN == e.getKeyCode()) {
                    tabla_conincidencias.requestFocus();
                    tabla_conincidencias.changeSelection(0, 0, false, false);
                }
                if (e.getSource() == tf_descripcion) {

                }
            }
        }
    }

    private void llenarCampos(Vehiculo resul) {
        //Fields
        tf_descripcion.setText(resul.getDescripcion());
        tf_chapa.setText(resul.getChapa());
        tf_motor.setText(resul.getDom_motor());
        tf_nro_unidad.setText(resul.getNro_unidad());
        tf_nro_chasis.setText(resul.getNro_chasis());
//        tf_config.setText(resul.getConfiguracionEjes().getDesignacion());

        //Combos
        combo_categoria.setSelectedItem(resul.getCategoria());
        combo_modelo.setSelectedItem(resul.getModelo());
        combo_propietario.setSelectedItem(resul.getPropietario());
        combo_chofer.setSelectedItem(resul.getChofer());
        combo_obra.setSelectedItem(resul.getObra());
        combo_modelo_anio.setSelectedItem(resul.getModelo_anio());

    }

    private void habilitarCampos(boolean b) {
        tf_descripcion.setEditable(b);
        tf_chapa.setEditable(b);
        tf_motor.setEditable(b);
        tf_nro_unidad.setEditable(b);
        tf_nro_chasis.setEditable(b);

        //radios
        radio_sin_chapa.setEnabled(b);
        radio_sin_chasis.setEnabled(b);
        radio_sin_nrp_motor.setEnabled(b);

        //Combos
        combo_categoria.setEnabled(b);
        combo_modelo.setEnabled(b);
        combo_marca.setEnabled(b);
        combo_propietario.setEnabled(b);
        combo_chofer.setEnabled(b);
        combo_obra.setEnabled(b);
        //combo_modelo_anio.setEnabled(b);

        //botones
        //bt_config.setEnabled(b);
    }

    class JTextFieldToUpperCase extends PlainDocument {

        public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException {
            super.insertString(offset, str.toUpperCase(), attr);
        }
    }
    
    class GrabarRegistro extends KeyAdapter {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getSource() == bt_grabar) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    grabar();
                }
            }
        }
    }
    
    class CambiarCampo extends KeyAdapter {

        @Override
        public void keyPressed(KeyEvent e) {
            accion(e);
        }

        public void accion(KeyEvent e) {
            if (e.getSource() == tf_descripcion) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    tf_chapa.requestFocus();
                }
            }
            if (e.getSource() == tf_chapa) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    tf_nro_unidad.requestFocus();
                }
            }
            if (e.getSource() == tf_nro_unidad) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    combo_marca.requestFocus();
                }
            }
            if (e.getSource() == combo_marca) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    combo_modelo.requestFocus();
                }
            }
            if (e.getSource() == combo_modelo) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    combo_categoria.requestFocus();
                }
            }
            if (e.getSource() == combo_categoria) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    combo_propietario.requestFocus();
                }
            }
            if (e.getSource() == combo_propietario) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    tf_motor.requestFocus();
                }
            }
            if (e.getSource() == tf_motor) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    tf_nro_chasis.requestFocus();
                }
            }
            if (e.getSource() == tf_nro_chasis) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    combo_chofer.requestFocus();
                }
            }
            if (e.getSource() == combo_chofer) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    combo_obra.requestFocus();
                }
            }
            if (e.getSource() == combo_obra) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    combo_estado.requestFocus();
                }
            }
            if (e.getSource() == combo_estado) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    bt_grabar.requestFocus();
                }
            }
            
        }

    }

}
